import { Controller, HttpCode, Get, Req, Res, Post, Body, Query, UploadedFile, UseInterceptors } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { FilesService as Service } from '../services/files.service';
import { from } from 'rxjs';
import { join } from 'path';

@Controller('files')
export class FilesController {

    constructor(private readonly service: Service) { }

    /**
    * 添加
    */
    @Post('/add')
    async add(@Body() body): Promise<any> {
        return this.service.add(body);
    }

    /**
     * 上传
    */
    @Post('/upload')
    @HttpCode(200)
    @UseInterceptors(FileInterceptor('file'))
    async upload(@UploadedFile() file, @Body() body): Promise<any> {
        return this.service.upload(file, body);
    }

    /**
    * 展示图片
    */
    @Get('img')
    getImg(@Query() query, @Req() req, @Res() response) {
        //console.log(req.headers.host);
        return this.service.showImg(query, response);
    }


}
